package com.common.rest.error;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ClientErrorMapper implements
		ExceptionMapper<InvalidRequestException> {
	
	private Logger log = LoggerFactory.getLogger(ClientErrorMapper.class); 
	
	@Override
	public Response toResponse(InvalidRequestException exception) {
		log.debug(exception.getMessage(), exception);
		ErrorMessage error = new ErrorMessage();
		error.setStatus("fail");
		error.setCode(exception.getCode());
		error.setMessage(exception.getMessage());
		return Response.status(Status.BAD_REQUEST)
				.entity(error)
				.type(MediaType.TEXT_PLAIN)
				.build();
	}

}
